import java.util.*;

public class test {
    //蓝桥杯 通关
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        //关卡数量和小蓝初始经验
        int n = in.nextInt();
        int exp = in.nextInt();
        //记录我们通过的关卡数
        int level = 0;
        //用于"通关所需经验"从小到大取出的小根堆
        PriorityQueue<int[]> queue = new PriorityQueue<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[3] - o2[3];
            }
        });
        //value存储部分关卡,key为解锁这些关卡的前置关卡
        HashMap<Integer, List<int[]>> map = new HashMap<>();
        for(int i = 0;i < n;i++){
            int[] arr = new int[4];
            //当前关卡
            arr[0] = i + 1;
            //该关卡的前置关卡(key)
            arr[1] = in.nextInt();
            //通关获得的exp
            arr[2] = in.nextInt();
            //通关最少需要的exp
            arr[3] = in.nextInt();
            //修改并存储key能解锁的部分关卡
            List<int[]> list = map.getOrDefault(arr[1],new ArrayList<>());
            list.add(arr);
            map.put(arr[1],list);
        }
        //将第一关存入优先队列
        queue.offer(map.remove(0).get(0));
        while(!queue.isEmpty()){
            //获取当前队顶关卡(通关经验最少的关卡)
            int[] arr = queue.remove();
            //不符合通关条件,break
            if(exp < arr[3]){
                break;
            }
            //获得经验,通过关卡+1
            exp += arr[2];
            level++;
            //传入当前通关关卡,解锁后续关卡
            List<int[]> list = map.remove(arr[0]);
            if(list != null) {
                for(int[] a : list){
                    queue.offer(a);
                }
            }
        }
        System.out.println(level);
        in.close();
    }
    //leetcode 123.图书整理 1
    class Solution {
        public int[] reverseBookList(ListNode head) {
            if(head == null){
                return new int[0];
            }
            int index = 1;
            ListNode node = head;
            ListNode cur = node.next;
            while(cur != null){
                ListNode curn = cur.next;
                cur.next = node;
                node = cur;
                cur = curn;
                index++;
            }
            head.next = null;
            int[] arr = new int[index];
            index = 0;
            while(node != null){
                arr[index++] = node.val;
                node = node.next;
            }
            return arr;
        }
    }
    //leetcode 125.图书整理2
    class CQueue {
        LinkedList<Integer> A;
        LinkedList<Integer> B;
        public CQueue() {
            A = new LinkedList<Integer>();
            B = new LinkedList<Integer>();
        }

        public void appendTail(int value) {
            A.addLast(value);
        }

        public int deleteHead() {
            if(!B.isEmpty()){
                return B.removeLast();
            }
            if(A.isEmpty()){
                return -1;
            }
            if(!A.isEmpty()){
                B.addLast(A.removeFirst());
                return B.remove();
            }
            return -1;
        }
    }
}
